<template>
  <div :id="id" :style="{ width: '100%', height: '100%' }"></div>
</template>

<script>
function getRandomNumber(m, n) {
  return Math.floor(Math.random() * (m - n + 1) + n)
}

let dataA = []
let dataB = []
let dataC = []
for (let index = 0; index < 4; index++) {
  dataA.push(getRandomNumber(80, 95))
  dataB.push(getRandomNumber(80, 95))
  dataC.push(getRandomNumber(80, 95))
}

var option = {
  title: {
    text: '云客服每月呼入总量(单位：万次)'
  },
  tooltip: {
    trigger: 'axis',
    axisPointer: {
      type: 'shadow'
    }
  },
  legend: {
    data: ['', '', ''],
    x: 'right',
    padding: [10, 50, 0, 0]
  },
  toolbox: {
    show: true,
    orient: 'vertical',
    left: 'right',
    top: 'center',
    feature: {
      mark: { show: true },
      dataView: { show: true, readOnly: false },
      magicType: { show: true, type: ['line', 'bar', 'stack', 'tiled'] },
      restore: { show: true },
      saveAsImage: { show: true }
    }
  },
  xAxis: [
    {
      type: 'category',
      axisTick: { show: false },
      data: ['2020第二季度', '2020第三季度', '2020第四季度', '2021第一季度']
    }
  ],
  yAxis: [
    {
      type: 'value'
    }
  ],
  series: [
    {
      name: '',
      type: 'bar',
      emphasis: {
        focus: 'series'
      },
      data: dataA
    },
    {
      name: '',
      type: 'bar',
      emphasis: {
        focus: 'series'
      },
      data: dataB
    },
    {
      name: '',
      type: 'bar',
      emphasis: {
        focus: 'series'
      },
      data: dataC
    }
  ]
}

export default {
  data() {
    return {
      id: new Date().getTime()
    }
  },

  mounted() {
    this.drawLine()
  },

  methods: {
    drawLine() {
      // 基于准备好的dom，初始化echarts实例
      let myChart = this.$echarts.init(document.getElementById(this.id))
      // 绘制图表
      myChart.setOption(option)
    }
  }
}
</script>

<style lang="scss" scoped></style>
